package sort;


import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
public class SortMapper extends Mapper<LongWritable, Text, NumberStr, NullWritable> {
    final NumberStr bean = new NumberStr();


    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1 读取一行文本，转为字符串，切分
        final String[] fields = value.toString().split("\t");
        //2 解析出各个字段封装成NumberStr对象
        bean.setValue(Long.parseLong(fields[0]));
        bean.setIndex(0L);
        //3 NumberStr作为key输出
        context.write(bean, NullWritable.get());
    }
}
